//整个ws服务使用的上下文，包含项目运行所用到的全局属性，例如：配置

package svc

import (
	"gitee.com/zxh/easy-chat/apps/im/immodels"
	"gitee.com/zxh/easy-chat/apps/im/ws/internal/config"
	"gitee.com/zxh/easy-chat/apps/task/mqclient"
)

type ServiceContext struct {
	//加载配置文件对象
	Config config.Config

	//加载模型
	immodels.ChatLogModel

	//加载mq客户端
	mqclient.MsgChatTransferClient
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		//创建配置文件对象
		Config: c,

		//创建模型
		ChatLogModel: immodels.MustNewChatLogModel(c.Mongo.Url, c.Mongo.Db),

		//创建mq客户端
		MsgChatTransferClient: mqclient.NewMsgChatTransferClient(c.MsgChatTransfer.Addrs, c.MsgChatTransfer.Topic),
	}
}
